//
//  BaseViewController.m
//  WXD头标签
//
//  Created by mac on 17/7/2.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "BaseViewController.h"


@interface BaseViewController ()

@end

@implementation BaseViewController
{
    UIWebView *webView;
}
-(instancetype)init{
    self = [super init];
    if (self)
    {
        self.view.backgroundColor = [UIColor whiteColor];
        topview = [[TopBarView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 60)];
        topview.backgroundColor = headColor;
        [self.view addSubview:topview];
        
        topview.delegate = self;
        
        //        topview.hidden = YES;
        
    }
    return self;
}
-(void)setTopViewHeight:(NSInteger)height
{
    [topview setFrame:CGRectMake(0, 0, SCREENWIDTH, height)];
}

-(void)makeLoading{
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,ScreenHeight/2-20,ScreenWidth,ScreenHeight/2)];
    
    webView.backgroundColor = [UIColor whiteColor];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"5-121204193935-51" ofType:@"gif"];
    NSURL *url = [NSURL URLWithString:path];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
    [self.view addSubview:webView];
    
}
-(void)removeLoading{
    [webView removeFromSuperview];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedRightButton:)];
    
    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    
    [self.view addGestureRecognizer:swipeLeft];
    
    
    
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedLeftButton:)];
    
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    
    [self.view addGestureRecognizer:swipeRight];
}
-(void)backActionOfdelegater
{
    
    if(self.presentingViewController){
        //modal view controller
        [[ViewManager shareInstance].NavigationController dismissViewControllerAnimated:YES completion:NULL];
        
        
    }else{
        [[ViewManager shareInstance].NavigationController popViewControllerAnimated:YES];
    }
}
- (void) tappedRightButton:(id)sender

{
    
    NSUInteger selectedIndex = [self.tabBarController selectedIndex];
    
    NSArray *aryViewController = self.tabBarController.viewControllers;
    
    if (selectedIndex < aryViewController.count - 1) {
        
        UIView *fromView = [self.tabBarController.selectedViewController view];
        
        UIView *toView = [[self.tabBarController.viewControllers objectAtIndex:selectedIndex + 1] view];
        
        [UIView transitionFromView:fromView toView:toView duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
            
            if (finished) {
                
                [self.tabBarController setSelectedIndex:selectedIndex + 1];
                
            }
            
        }];
        
    }
    
    
    
}


- (void) tappedLeftButton:(id)sender

{
    
    NSUInteger selectedIndex = [self.tabBarController selectedIndex];
    
    
    
    if (selectedIndex > 0) {
        
        UIView *fromView = [self.tabBarController.selectedViewController view];
        
        UIView *toView = [[self.tabBarController.viewControllers objectAtIndex:selectedIndex - 1] view];
        
        [UIView transitionFromView:fromView toView:toView duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
            
            if (finished) {
                
                [self.tabBarController setSelectedIndex:selectedIndex - 1];
                
            }
            
        }];
        
    }
    
}

-(void)setToptittle:(NSString *)Tittle{
    [topview setToptittle:Tittle];
}
-(void)setTopTittleColor:(UIColor *)color{
    [topview setTopTittleColor:color];
}
-(void)setTopBgColor:(UIColor *)color{
    [topview setTopBgColor:color];
}
-(void)setBackBtnHide:(BOOL)hide{
    [topview setBackBtnHide:hide];
}
-(void)setBackBtnImage:(UIImage *)image{
    [topview setBackBtnImage:image];
}
-(void)setTopLineHide:(BOOL)hide{
    [topview setTopLineHide:hide];
}
-(void)setBackBtnTittle:(NSString *)tittle{
    [topview setBackBtnTittle:tittle];
}
-(void)setTopViewHide:(BOOL)hide{
    topview.hidden = hide;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}















//客户端提示信息
- (void)alert:(NSString *)title msg:(NSString *)msg
{
    UIAlertController *alert=[UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];//创建警报窗口
    UIAlertAction *cancel=[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];//添加取消按钮
    [alert addAction:cancel];//添加到警报窗口
    [self presentViewController:alert animated:YES completion:nil];//添加到视图
}




@end
